package socket.server_socket;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class Client {
    @Test
    public void demo_01() {
        try(Socket socket = new Socket()) {
            SocketAddress address = new InetSocketAddress("localhost", 1024);
            socket.connect(address);
            StringBuilder buffer = new StringBuilder();
            InputStreamReader reader = new InputStreamReader(socket.getInputStream(), "ASCII");
            for(int c = reader.read(); c != -1; c = reader.read()) {
                buffer.append((char) c);
            }
            System.out.println(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
